package com.android.launcher3;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import android.widget.Scroller;

public class AppMenu extends FrameLayout implements
		MenuItemView.UninstallableMarkerDrawParent {

	final Camera mCamera = new Camera();
	private Bitmap mEditBg;
	private Bitmap mImage;
	private Paint mPaint;
	private Rect mTmpRect;
	private Animate[] mChildAnimate;
	private boolean mEnabledChildAnimation;
	private float roate_degree = 0.0f;
	private int mAppHeight;
	private int mAppWidth;
	private int mColumnNum;
	private int mDeleteIconRightOffset;
	private int mDeleteIconTopOffset;
	private int mEditIndex;
	private int mEditLeftOffset;
	private int mEditTopOffset;
	private int mIconWidth;
	private int mItemNumOfPage;
	private int mLRPadding;
	private int mOrientation = 1;
	private int mRightOffset;
	private int mTopOffset;
	private int mVerticalSpace;
	public static final String DEBUG_TAG = "Launcher";
	public static final String TAG = "AppMenu";
	protected static int mAninmationType = 0;
	private static int originalAninmationType = 0;

	int distance = 75;

	/**
	 * 完整.
	 * 
	 * @param context
	 */
	public AppMenu(final Context context) {
		this(context, null);
	}

	/**
	 * 完整.
	 * 
	 * @param context
	 * @param defStyle
	 */
	public AppMenu(final Context context, final int defStyle) {
		super(context);
		Rect localRect = new Rect();
		this.mTmpRect = localRect;
		this.mEditIndex = -1;
		this.mOrientation = defStyle;
		init();
	}

	/**
	 * 完整.
	 * 
	 * @param context
	 * @param attrs
	 */
	public AppMenu(final Context context, final AttributeSet attrs) {
		this(context, attrs, 0);
	}

	/**
	 * 完整.
	 * 
	 * @param paramContext
	 * @param attrs
	 * @param defStyle
	 */
	public AppMenu(final Context paramContext, final AttributeSet attrs,
			final int defStyle) {
		super(paramContext, attrs, defStyle);

		Rect localRect = new Rect();
		this.mTmpRect = localRect;
		this.mEditIndex = -1;
		init();
	}

	public void drawChildUninstallableMarker(final Canvas canvas, final View v) {
		LogUtils.d(TAG, "drawChildUninstallableMarker");

		if (this.mImage != null) {
			// Log.e(TAG,"drawChildUninstallableMarker");
			Object localObject = v.getTag();

			if ((localObject != null)
					&& (localObject instanceof ApplicationInfo)
					&& (!((ApplicationInfo) localObject).systemApp)) {
				Bitmap localBitmap = this.mImage;
				float f1 = v.getWidth() - localBitmap.getWidth()
						- (v.getWidth() - this.mIconWidth) / 2
						- this.mDeleteIconRightOffset;
				canvas.drawBitmap(localBitmap, f1, this.mDeleteIconTopOffset,
						this.mPaint);
			}
		}
	}

	public int getChildHeight() {
		return this.mAppHeight;
	}

	public int getChildWidth() {
		return this.mAppWidth;
	}

	public int getLRPadding() {
		return this.mLRPadding;
	}

	public void myLayout(final int mScrollX) {
//		Log.e(TAG, "myLayout");
//		Log.e(TAG, "mScrollX " + mScrollX);
//		Log.e(TAG, "myLayout aninmationType " + mAninmationType);
//		Log.e(TAG, "this.mAppHeight  " + this.mAppHeight);
//		Log.e(TAG, "mAppWidth   " + this.mAppWidth);
//		Log.e(TAG, "mAninmationType " + mAninmationType);

		switch (mAninmationType) {
		// 默认
		case 0:
			return;

			// 双子星
		case 2: {

			int deltX = (mScrollX - this.getLeft());

//			if (deltX < 0) {
//				this.setBackgroundColor(Color.RED);
//			} else {
//				this.setBackgroundColor(Color.GRAY);
//			}
			
			// 不要删除
			float parent_width = this.mMeasuredWidth;

			if (deltX >= this.mMeasuredWidth || deltX <= -this.mMeasuredWidth) {
				deltX = 0;
			}

//			deltX = deltX % (int) parent_width;
//			Log.e(TAG,"parent_width   "+parent_width );

			int count = this.getChildCount();

			for (int i = 0; i < count; i++) {
				View v = this.getChildAt(i);

				int column = i % 4;

				int row = i / 4;

				// 当 column 越小，移动距离越大
				// 当 column 为0 的时候，x 应该接近 deltX 才对 .

				// x的值不能大于 deltX ，只能小于 deltX
				// y 轴的重叠有问题，应该是最后重叠在一个位置上，而不是现在的2个位置.

				// int left=column * width + deltX;
				int left = 0;

				if (deltX > 0) {
					int x = (int) (mAppWidth * (column + 1) / parent_width * deltX);

					left = column * mAppWidth + deltX - x;
				} else {
					// Log.e(TAG,"deltX <  0   ");
					int x = (int) (mAppWidth * (4 - column) / parent_width * deltX);

//					left = column * width + deltX - x;
//					if (p.getChildAt(0) == this && column == 0) {
//						Log.e(TAG, "x " + x);
//					}
					left = column * mAppWidth + deltX - x;
				}

				// 第2个向下移动半个位置，第3个向上移动半个位置，这样就可以重叠了
				// 第1个向下移动1个半的位置，第4个向上移动1个半的位置，这样就可以重叠了

				// 第1个向下移动1个半的位置 ， 第2个向下移动半个位置
				// 第3个向上移动半个位置 ， 第4个向上移动1个半的位置

				// 第0个向下移动1个半的位置 ， 第1个向下移动半个位置
				int y = 0;

				if (row <= 1) {
					y = (int) ((1.5f - row) * mAppHeight / parent_width * deltX);
				} else {
					row = 3 - row;
					y = -(int) ((1.5f - row) * mAppHeight / parent_width * deltX);
				}

				if (deltX < 0) {
					y = -y;
				}

				// Log.e(TAG,""+left);
				int top = i / 4 * mAppHeight + y;

				// Log.e(TAG,""+top);
				v.layout(left, top, left + mAppWidth, top + mAppHeight);
			}
			break;
		}

			// 弦
		case 5: {
		}

			// 百叶窗 需配合 drawChild
		case 3: {

			int deltX = (mScrollX - this.getLeft());

			if (deltX >= this.mMeasuredWidth || deltX <= -this.mMeasuredWidth) {
				deltX = 0;
			}

//			if (deltX < 0) {
//				this.setBackgroundColor(Color.RED);
//			} else {
//				this.setBackgroundColor(Color.GRAY);
//			}

			int count = this.getChildCount();
			// 保证的滑动的时候图标不动
			for (int i = 0; i < count; i++) {
				View v = this.getChildAt(i);
				int column = i % 4;
				int left = column * mAppWidth + deltX;
				int top = i / 4 * mAppHeight;
				v.layout(left, top, left + mAppWidth, top + mAppHeight);
			}

			break;
		}

			// 滚咕噜咕噜滚
		case 4: {
			int left = 0;
			int top = 0;
			int R = 120;
			int topX = 118;
			int topY = 5;
			int z = 11;
			// Log.e(TAG," "+this.getId());

			// int index=((ViewGroup)this.getParent()).indexOfChild(this);

			// 圆心在哪里？ x=topX+120 y=topY+120;

//			int count = this.getChildCount();
//			for (int i = 0; i < count; i++) {
//				View v = this.getChildAt(i);
//				Log.e(TAG, "	v.getLeft() " + v.getLeft());
//				Log.e(TAG, "	getTop () " + v.getTop());
//			}

			// Log.e(TAG,"mScrollX-this.getLeft()  "+
			// (mScrollX-this.getLeft()));

			// if(true)
			// break;
			int deltX = (mScrollX - this.getLeft());

			if (deltX >= this.mMeasuredWidth || deltX <= -this.mMeasuredWidth) {
				deltX = 0;
			}

//			if (index == 0) {
//				Log.e(TAG, " deltX " + deltX);
//			}
//			deltX=deltX%this.mMeasuredWidth;

			if (deltX < 0) {
				deltX = 0 - deltX;
			}

			if (deltX <= distance) {
				for (int i = 0; i < 16; i++) {
					View v = this.getChildAt(i);
					if (v == null) {
						break;
					}

					left = topX
							+ (int) (Math.sin(Math.toRadians(22.5f * (3 - i)
									+ z)) * R);

					left = (int) ((i - 4 * (i / 4)) * mAppWidth + deltX
							/ (distance * 1.0f)
							* (left - (i - 4 * (i / 4)) * mAppWidth));

					top = topY
							+ R
							- (int) (Math.cos(Math.toRadians(22.5f * (3 - i)
									+ z)) * R);

					top = (int) (mAppHeight * (i / 4) + deltX
							/ (distance * 1.0f) * (top - mAppHeight * (i / 4)));

					v.layout(left, top, left + mAppWidth, top + mAppHeight);
				}

			} else
			// 此时应该是圆形的
			if (deltX > distance) {
				float d = -(deltX - distance) / 90.0f;

				// Log.e(TAG,"d== "+d);
				for (int i = 0; i < 16; i++) {
					View v = this.getChildAt(i);

					if (v == null) {
						break;
					}

					left = topX
							+ (int) (Math.sin(Math.toRadians(22.5f * (3 - i)
									+ z)
									+ d) * R);
					top = topY
							+ R
							- (int) (Math.cos(Math.toRadians(22.5f * (3 - i)
									+ z)
									+ d) * R);
					v.layout(left, top, left + mAppWidth, top + mAppHeight);
				}
			}

			break;
		}

		}
	}

	@Override
	public void requestChildFocus(final View child, final View focused) {
		LogUtils.d(TAG, "requestChildFocus");
		super.requestChildFocus(child, focused);

		if (child != null) {
			Rect localRect = new Rect();
			child.getDrawingRect(localRect);
			requestRectangleOnScreen(localRect);
		}
	}

	public static void setAninmationType(final int aninmationType) {
		mAninmationType = aninmationType;
		originalAninmationType = aninmationType;
		// Log.e(TAG,"setAninmationType "+aninmationType2);
	}

	public void setBitmap(final Bitmap bm) {
		this.mImage = bm;
	}

	public void setEditBg(final Bitmap bm) {
		this.mEditBg = bm;
	}

	public void setEditIndex(final int index) {
		this.mEditIndex = index;
	}

	public void setEnabledChildAnimation(final boolean enabled) {
		this.mEnabledChildAnimation = enabled;
	}

	@Override
	protected void dispatchDraw(final Canvas canvas) {
		LogUtils.d(TAG, "dispatchDraw-start");

		// boolean restore=false;
		// int mScrollX= ((ViewGroup)this.getParent()).getScrollX();
		//
		// int deltX=(mScrollX-this.getLeft());
		//
		// if(deltX<distance&&deltX>=0){
		//
		// }
		// else{
		// canvas.save();
		// canvas.rotate(- 90* (deltX/320.0f),mScrollX,170);
		// restore=true;
		// }
		super.dispatchDraw(canvas);

		// if(restore){
		// canvas.restore();
		// }
		View localView;

		if ((this.mEditBg != null) && (this.mEditIndex != -1)) {
			int i = this.mEditIndex;
			localView = getChildAt(i);

			if ((localView != null)
					&& (localView.getVisibility() != View.VISIBLE)) {
				Bitmap localBitmap = this.mEditBg;
				int j = localView.getLeft();
				int k = this.mEditLeftOffset;
				float f1 = j + k;
				int m = localView.getTop();
				int n = this.mEditTopOffset;
				float f2 = m + n;
				Paint localPaint = this.mPaint;
				canvas.drawBitmap(localBitmap, f1, f2, localPaint);
			}
		}

		LogUtils.d(TAG, "dispatchDraw-end");
	}

	AccelerateInterpolator mAccelerateInterpolator = new AccelerateInterpolator();

	DecelerateInterpolator mDecelerateInterpolator = new DecelerateInterpolator();

	LinearInterpolator mLinearInterpolator = new LinearInterpolator();

	/**
	 * 随机特效处理
	 */
	protected static void checkRandomAnimation() {
		if (originalAninmationType == 1) {
			mAninmationType = (int) (Math.random() * 12) + 2;
		}
		// Log.e(TAG,"mAninmationType "+mAninmationType);

	}

	@Override
	protected boolean drawChild(final Canvas canvas, final View view,
			final long drawingTime) {
		int mScrollX = ((ViewGroup) this.getParent()).getScrollX();
		canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG
				| Paint.FILTER_BITMAP_FLAG));

		// 不要删除
//		int mSrollX = ((ViewGroup) this.getParent()).getScrollX();
//		int deltaX = mSrollX - this.getLeft();
//		canvas.save();
//		int centerX = view.getLeft() + view.getWidth() / 2;
//		int centerY = view.getTop() + view.getHeight() / 2;
//		canvas.translate(centerX, centerY);
//		float degree = 360 * deltaX / 320.0f;
//		canvas.rotate(degree);
//		canvas.translate(-centerX, -centerY);
		boolean restore = false;

		// Log.e(TAG,"drawChild  mAninmationType "+mAninmationType);
		switch (mAninmationType) {
		// 百叶窗
		case 3: {
			int deltaX = mScrollX - this.getLeft();

//			if (deltaX >= this.mMeasuredWidth || deltaX <= -this.mMeasuredWidth) {
//				deltaX = 0;
//			}
//
//			if (deltaX == 0) {
//				break;
//			}

			canvas.save();

			int centerX = view.getLeft() + this.mAppWidth / 2;

			int centerY = view.getTop() + this.mAppHeight / 2;

			// canvas.translate(centerX,centerY);
			float degree = 180 * deltaX / (this.getWidth() * 1.0f);

//			if (Math.abs(degree) > 170) {
//				canvas.restore();
//				return true;
//			}
//			Log.e(TAG, degree + "");

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.translate(centerX, centerY, 0);
			mCamera.rotateY(-degree);
			mCamera.translate(-centerX, -centerY, 0);
			mCamera.getMatrix(ctm);
			canvas.concat(ctm);
			mCamera.restore();
			restore = true;
			break;
		}
			// 滚咕噜咕噜滚
		case 4: {

			int deltX = (mScrollX - this.getLeft());

//			if (deltX >= this.mMeasuredWidth || deltX <= -this.mMeasuredWidth) {
//				deltX = 0;
//			}
//
//			if (deltX == 0) {
//				break;
//			}

			int centerX = view.getLeft() + mAppWidth / 2;
			// int centerX = view.getLeft() ;
			int centerY = view.getTop() + mAppHeight / 2;
			// int centerY = view.getTop();

			// ViewGroup p = (ViewGroup) view.getParent();

			int index = this.indexOfChild(view);

			int column = index % 4;

			int row = index / 4;

			roate_degree = 0;

			if (deltX < distance && deltX >= 0) {

				roate_degree = (deltX / (distance * 1.0f) * -(column * 22.5f
						+ row * 90 + 90));

			} else {
				// float d = -(deltX - distance) / 90.0f;
				roate_degree = -(column * 22.5f + row * 90 + 90);
				// roate_degree = - index *22.5f - 90;
			}

			canvas.save();
			canvas.rotate(roate_degree, centerX, centerY);
			restore = true;

			break;
		}
			// 弦
		case 5: {

			int index = this.indexOfChild(view);

			int column = index % 4;

			int deltaX = mScrollX - this.getLeft();

//			if (deltaX >= this.mMeasuredWidth || deltaX <= -this.mMeasuredWidth) {
//				deltaX = 0;
//			}

			// Log.e(TAG,"mn "+column);
			// Log.e(TAG,"deltaX/80  "+ deltaX/80);

//			if (index == 0) {
//				Log.e(TAG, "mScrollX  " + mScrollX);
//			}
//
//			if (deltaX < 0) {
//				deltaX = -deltaX;
//			}

			if (deltaX > 0 && deltaX / this.mAppWidth == 3 - column) {
				canvas.save();
				int centerX = view.getLeft() + view.getWidth() / 2;
				int centerY = 0;
				float degree = 180 * mDecelerateInterpolator
						.getInterpolation((deltaX % this.mAppWidth / (this.mAppWidth * 1.0f)));
				// degree=0+90*(deltaX % 80 / 80.0f);

				if (index == 2) {
					// Log.e(TAG,"degree "+degree);
				}

//				if (degree % 360 > 95) {
//					return true;
//				}

				Matrix ctm = new Matrix();
				mCamera.save();
				mCamera.translate(centerX, centerY, 0);
				mCamera.rotateY(-degree);
				mCamera.translate(-centerX, -centerY, 0);
				mCamera.getMatrix(ctm);
				canvas.concat(ctm);
				mCamera.restore();
				restore = true;
			}

			else if (deltaX < 0 && -deltaX / this.mAppWidth == column) {

				// Log.e(TAG,"deltaX<0");
				// Log.e(TAG,"index "+index);
				canvas.save();

				int centerX = view.getLeft() + view.getWidth() / 2;
				int centerY = 0;

				// -90至 -0

				if (Math.abs(deltaX) % this.mAppWidth >= this.mAppWidth / 2) {
					return true;
				}

				float degree = -90
						* mAccelerateInterpolator
								.getInterpolation((-deltaX % (this.mAppWidth / 2 * 1.0f))
										/ (this.mAppWidth / 2 * 1.0f));

//				if (index == 3) {
//				}
				
				Matrix ctm = new Matrix();
				mCamera.save();
				mCamera.translate(centerX, centerY, 0);
				mCamera.rotateY(-degree);
				mCamera.translate(-centerX, -centerY, 0);
				mCamera.getMatrix(ctm);
				canvas.concat(ctm);
				mCamera.restore();
				restore = true;
			}
			break;

		}
		}

		if ((this.mImage != null) && (this.mEditBg != null)) {
			canvas.drawBitmap(this.mEditBg, view.getLeft()
					+ this.mEditLeftOffset,
					view.getTop() + this.mEditTopOffset, this.mPaint);
		}

		boolean drawChild = super.drawChild(canvas, view, drawingTime);

		if (restore) {
			canvas.restore();
		}

		return drawChild;
	}

	@Override
	protected void onLayout(final boolean changed, final int paramInt1,
			final int paramInt2, final int paramInt3, final int paramInt4) {
		LogUtils.d(TAG, "onLayout");

		// Log.e(TAG, "onLayout");
		Rect localRect = this.mTmpRect;
		int k = getChildCount();
		// Log.e(TAG, "onLayout  getChildCount "+k);
		int n = 0;

		while (n < k) {

			View localView = getChildAt(n);

			if (localView.getVisibility() != View.GONE) {
				int left = this.mLRPadding + localView.getMeasuredWidth()
						* (n % this.mColumnNum);
				int top = this.mTopOffset + localView.getMeasuredHeight()
						* (n / this.mColumnNum) + this.mVerticalSpace
						* (n / this.mColumnNum);
				int right = left + localView.getMeasuredWidth();
				int bottom = top + localView.getMeasuredHeight();
				localView.getHitRect(localRect);

				if ((!localRect.isEmpty()) && (this.mEnabledChildAnimation)
						&& n < this.mItemNumOfPage) {
					localRect.set(left, top, right, bottom);
					this.mChildAnimate[n].start(localView, localRect, 300);
				} else {
					localView.layout(left, top, right, bottom);
				}
			}

			n++;
		}
	}

//	@Override
//	public void addView(View child) {
//		super.addView(child);
//		if (((ViewGroup) this.getParent()).indexOfChild(this) == 0) {
//			Log.e(TAG, "addView " + this.getChildCount());
//		}
//	}

	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		LogUtils.d(TAG, "onMeasure");
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

		int widthSpecSize = View.MeasureSpec.getSize(widthMeasureSpec);
		// int heightSpecSize = View.MeasureSpec.getSize(heightMeasureSpec);
		int lrPadding = this.mLRPadding * 2;
		int m = widthSpecSize - lrPadding;
		int n = this.mRightOffset;
		int i1 = m - n;
		int columnNum = this.mColumnNum;
		int i3 = i1 / columnNum;
		this.mAppWidth = i3;

		int appWidth = this.mAppWidth;
		int appHeight = this.mAppHeight;
		widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(appWidth,
				MeasureSpec.EXACTLY);
		heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(appHeight,
				MeasureSpec.EXACTLY);

		int childCount = getChildCount();
		int childIndex = 0;

		while (childIndex < childCount) {
			getChildAt(childIndex).measure(widthMeasureSpec, heightMeasureSpec);
			childIndex++;
		}
	}

	protected void setChildrenDrawingCacheEnabled(final boolean enabled) {
		int i = getChildCount();
		int j = 0;

		while (j < i) {
			View localView = getChildAt(j);
			localView.setDrawingCacheEnabled(enabled);
			localView.buildDrawingCache(true);
			j++;
		}
	}

	@Override
	protected void setChildrenDrawnWithCacheEnabled(final boolean enabled) {
		super.setChildrenDrawnWithCacheEnabled(enabled);
	}

	void cellToPoint(final int paramInt, final int[] paramArrayOfInt) {
		int i = this.mColumnNum;
		int j = paramInt / i;
		int k = this.mColumnNum;
		int m = paramInt % k;
		int n = this.mLRPadding;
		int i1 = this.mAppWidth * m;
		int i2 = n + i1;
		paramArrayOfInt[0] = i2;

		int i3 = this.mTopOffset;
		int i4 = this.mAppHeight;
		int i5 = this.mVerticalSpace;
		int i6 = (i4 + i5) * j;
		int i7 = i3 + i6;
		paramArrayOfInt[1] = i7;
	}

	void cellToPoint(final View paramView, final int[] paramArrayOfInt) {
		Rect localRect = new Rect();
		paramView.getHitRect(localRect);

		if (localRect.isEmpty()) {
			int i = indexOfChild(paramView);
			cellToPoint(i, paramArrayOfInt);

			return;
		}

		int j = localRect.left;
		paramArrayOfInt[0] = j;

		int k = localRect.top;
		paramArrayOfInt[1] = k;
	}

	private void init() {
		// this.setBackgroundResource(R.drawable.wallpaper_beach);
		setClickable(true);

		Paint localPaint = new Paint();
		this.mPaint = localPaint;

		Resources localResources = getResources();
		// Configuration localConfiguration = localResources.getConfiguration();
		Context localContext = getContext();

		int i = -1;

//		 贺辉 2011年10月27日11:00:49 注释
//		int j = localConfiguration.orientation;
//		int k = this.mOrientation;
//
//		if (j != k) {
//			i = localConfiguration.orientation;
//			localConfiguration.orientation = this.mOrientation;
//
//			DisplayMetrics localDisplayMetrics1 = localResources
//					.getDisplayMetrics();
//			localResources.updateConfiguration(localConfiguration,
//					localDisplayMetrics1);
//		}

		this.mColumnNum = LauncherConfig.getColumnNo(localContext);

		this.mItemNumOfPage = localContext.getResources().getInteger(
				R.integer.item_num_of_page);

		this.mChildAnimate = new Animate[this.mItemNumOfPage];

		this.mAppHeight = localResources
				.getDimensionPixelSize(R.dimen.menu_item_height);

		this.mVerticalSpace = localResources
				.getDimensionPixelSize(R.dimen.menu_item_vertical_space);

		this.mEditLeftOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_edit_left_offset);

		this.mEditTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_edit_top_offset);

		this.mDeleteIconTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_item_top_space)
				+ localResources
						.getDimensionPixelSize(R.dimen.menu_delete_icon_top_offset);

		this.mDeleteIconRightOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_delete_icon_right_offset);
		this.mIconWidth = localResources
				.getDimensionPixelSize(R.dimen.menu_item_icon_width);
		this.mTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_top_offset2);
		this.mLRPadding = localResources
				.getDimensionPixelSize(R.dimen.menu_lr_padding);
		this.mRightOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_right_offset);

//		 贺辉 2011年10月27日11:00:49 注释
//		if (i != -1) {
//			DisplayMetrics localDisplayMetrics2 = localResources
//					.getDisplayMetrics();
//			localConfiguration.orientation = i;
//			localResources.updateConfiguration(localConfiguration,
//					localDisplayMetrics2);
//		}

		if (mItemNumOfPage > 0) {
			for (i = 0; i < mItemNumOfPage; i++) {
				this.mChildAnimate[i] = new Animate();
			}
		}

		setAnimationCacheEnabled(false);

		this.setBackgroundColor(Color.parseColor("#00000000"));

	}

	class Animate implements Runnable {
		private Rect mRect;
		private Scroller mScroller;
		private View mTargetView;

		/**
		 * Creates a new Animate object.
		 */
		Animate() {
			this.mRect = new Rect();

			Context localContext = AppMenu.this.getContext();
			Scroller localScroller = new Scroller(localContext,
					new DecelerateInterpolator());
			this.mScroller = localScroller;
		}

		public boolean isEnd() {
			return !this.mScroller.computeScrollOffset();
		}

		public void run() {
			Scroller localScroller = this.mScroller;
			boolean bool1 = localScroller.computeScrollOffset();
			int i = localScroller.getCurrX();
			int j = localScroller.getCurrY();
			View localView = this.mTargetView;

			if (bool1) {
				int k = localView.getWidth() + i;
				int m = localView.getHeight() + j;
				localView.layout(i, j, k, m);
				AppMenu.this.invalidate();
				AppMenu.this.post(this);

				return;
			} else {
				int n = localView.getWidth() + i;
				int i1 = localView.getHeight() + j;
				localView.layout(i, j, n, i1);
				AppMenu.this.invalidate();
			}
		}

		public void start(final View view, final Rect paramRect,
				final int paramInt) {
			stop();
			this.mTargetView = view;

			Rect localRect = this.mRect;
			view.getHitRect(localRect);

			Scroller localScroller = this.mScroller;
			int i = localRect.left;
			int j = localRect.top;
			int k = paramRect.left;
			int m = localRect.left;
			int n = k - m;
			int i1 = paramRect.top;
			int i2 = localRect.top;
			int i3 = i1 - i2;
			int i4 = paramInt;
			localScroller.startScroll(i, j, n, i3, i4);
			AppMenu.this.post(this);
		}

		public void stop() {
			AppMenu.this.removeCallbacks(this);
		}
	}
}
